package com.qvtu.springboot.controller;


import com.github.pagehelper.PageInfo;
import com.qvtu.springboot.Common.Result;
import com.qvtu.springboot.entity.Admin;
import com.qvtu.springboot.service.AdminService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminService adminService;

//    新增数据
    @PostMapping("/add")
    public Result add(@RequestBody Admin admin){
        adminService.add(admin);
        return Result.success();
    }

//    删除数据
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id){
        adminService.deleteById(id);
        return Result.success();
    }

//    批量删除数据
    @DeleteMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        adminService.deleteBatch(ids);
        return Result.success();
    }

//    修改数据
    @PutMapping("/update")
    public Result update(@RequestBody Admin admin){
        adminService.update(admin);
        return Result.success();
    }

//    根据id查询数据
    @GetMapping("/seleteById/{id}")
    public Result selectById(@PathVariable Integer id){
        Admin admin=adminService.selectById(id);
        return Result.success(admin);
    }
//    查询所有数据
    @GetMapping("selectAll")
    public Result selectAll(Admin admin){
        List<Admin> list=adminService.selectAll(admin);
        return Result.success(list);
    }

//    分页查询
    @GetMapping("selectPage")
    public Result selectPage(Admin admin,@RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize){
        PageInfo<Admin> pageInfo=adminService.selectPage(admin,pageNum,pageSize);
        return Result.success(pageInfo);
    }
}
